const App = {
    // mixins: [Query],//配置文件，路径/utils/mixins.js
    data() {
        return {
            getYMDHMSDate,
            accAdd,
            relativePath: '',
            account: {},
            page: {
                activeName: 'first',
                SQLSerialNumber: 't_personal_points_change_log',
                PaginationNumber: 1, //页码
                RowAmount: 10,
                Condition: window.btoa(unescape(encodeURIComponent("%%,%%")))
            },
            tableData: [],
            dataForm:[],
            Total: 0,
            dialogVisible:false,
            fileUrl:'',
            showDialog1:false,
        }
    },
    mounted() {
        let ls_URL = window.location.href;
        this.relativePath = ls_URL.substring(
            ls_URL.lastIndexOf("view"),
            ls_URL.length
        );
        this.nodeKey = getQueryObject(ls_URL, "nodeKey");// 获取 nodeKey 参数
        this.page.Condition = window.btoa(unescape(encodeURIComponent("%%,%" + this.nodeKey + "%")))
        this.handleShow(this.nodeKey);
        this.getList(this.page);
    },
    methods: {
        handleShow1(row) {
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryByTableNameWithOriginal`,
                method: "post",
                data: {
                    Data: 'personal_points_change_log_attachment',
                    Condition: `Log_SerialNumber='${row.Log_SerialNumber}'`,
                },
                success: (res) => {
                    $.ajax({
                        headers: requestHeaders(),
                        url: `${mh}/generalBusiness/generalQueryByTableNameWithOriginal`,
                        method: "post",
                        data: {
                            Data: 'personal_points_application_attachment',
                            Condition: `Personal_Points_Application_SerialNumber='${row.Object_SerialNumber}'`,
                        },
                        success: (res1) => {
                            this.dataForm = [...res,...res1];
                            this.dialogVisible = true;
                        },
                        complete: (XMLHttpRequest) => {
                            requestPretreatment(XMLHttpRequest)
                        },
                    })
                    
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest)
                },
            });
            
        },
        preview(row) {
            this.fileUrl = photo + row.Attachment_URL;
            this.showDialog1 = true;
        },
        async download(row) {
            // if (row.Attachment_URL) {
            //     window.open(photo + row.Attachment_URL)
            // }
            let apiUrl = photo + row.Attachment_URL;
            let fileName = apiUrl.split('/').pop();
            try {
                const response = await fetch(apiUrl);
                const blob = await response.blob();
                const url = window.URL.createObjectURL(blob);

                const a = document.createElement('a');
                a.href = url;
                a.download = fileName || 'download';
                document.body.appendChild(a);
                a.click();

                // 清理
                setTimeout(() => {
                    document.body.removeChild(a);
                    window.URL.revokeObjectURL(url);
                }, 100);
            } catch (error) {
                console.error('下载失败:', error);
            }
        },
        handleClick() {
            if (this.page.activeName == 'first') {
                this.page.ExtensionCondition = window.btoa(unescape(encodeURIComponent("")));
            } else if (this.page.activeName == 'second') {
                this.page.ExtensionCondition = window.btoa(unescape(encodeURIComponent("AND personal_points_change_log.Points_Type = '1'")));
            } else if (this.page.activeName == 'three') {
                this.page.ExtensionCondition = window.btoa(unescape(encodeURIComponent("AND personal_points_change_log.Points_Type = '0'")));
            }
            this.getList(this.page);
        },
        handleSizeChange(newSize) {
            this.page.PaginationNumber = 1;
            this.page.RowAmount = newSize;
            this.getList(this.page);
        },
        handleCurrentChange(newPage) {
            this.page.PaginationNumber = newPage;
            this.getList(this.page);
        },
        handleShow(val) {
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryBySQLSerialNumber`,
                method: "post",
                data: {
                    SQLSerialNumber: 'f_personal_points_account',
                    Condition: window.btoa(unescape(encodeURIComponent(val))),
                    ExtensionCondition: ''
                },
                success: (res) => {
                    this.account = res[0];
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest)
                }
            })
        },
        getList(data) {
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
                method: "post",
                data,
                success: (res) => {
                    this.Total = res.TotalRows;//总数量
                    this.tableData = res.Rows;
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest)
                }
            })
        },
        goBack() {
            window.history.back();
        },
    },
};

const { createApp } = Vue;
const app = createApp(App);
//这种方式是引入全部图标，无需单个引入
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component);
}
const ElMessage = ElementPlus.ElMessage;
app.component('yl-online-preview', ylOnlinePreview);
app.use(ElementPlus, { locale: zhCn });
app.mount("#app");
